//
//  BaseNavController.swift
//  ShouChong
//
//  Created by 陈友文 on 2024/6/19.
//

import UIKit

class BaseNavController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        if #available(iOS 15, *) {
            let appearance = UINavigationBarAppearance()
            appearance.configureWithOpaqueBackground()
            appearance.shadowImage = UIImage()
            appearance.shadowColor = UIColor.clear
            appearance.backgroundColor = UIColor(named: "color_bg")
            self.navigationBar.standardAppearance = appearance
        } else {
            self.navigationBar.isTranslucent = false
            self.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
            self.navigationBar.shadowImage = UIImage()
            self.navigationBar.barTintColor = UIColor(named: "color_bg")
        }
    }
    

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if viewControllers.count > 0 {
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(image:UIImage.systemImage(systemName: "chevron.left", tintColor: UIColor(named: "color_text_black")!), style: .plain, target: self, action: #selector(navBack))
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func navBack() {
        self.popViewController(animated: true)
    }

}
